<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yang-da-xiong.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="前言opencv中有关图像绘制的部分">
<meta property="og:type" content="article">
<meta property="og:title" content="opencv学习笔记之绘制图形">
<meta property="og:url" content="https://yang-da-xiong.gitee.io/2022/02/17/opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E7%BB%98%E5%88%B6%E5%9B%BE%E5%BD%A2/index.html">
<meta property="og:site_name" content="杨大熊的代码世界">
<meta property="og:description" content="前言opencv中有关图像绘制的部分">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/17005c9a98954ff680d83be86d93074b.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="article:published_time" content="2022-02-17T05:04:41.686Z">
<meta property="article:modified_time" content="2022-02-18T14:50:59.188Z">
<meta property="article:author" content="杨大熊">
<meta property="article:tag" content="c++">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/17005c9a98954ff680d83be86d93074b.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">

<link rel="canonical" href="https://yang-da-xiong.gitee.io/2022/02/17/opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E7%BB%98%E5%88%B6%E5%9B%BE%E5%BD%A2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>opencv学习笔记之绘制图形 | 杨大熊的代码世界</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">杨大熊的代码世界</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://yang-da-xiong.gitee.io/2022/02/17/opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E7%BB%98%E5%88%B6%E5%9B%BE%E5%BD%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="杨大熊">
      <meta itemprop="description" content="各类IT知识分享">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="杨大熊的代码世界">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          opencv学习笔记之绘制图形
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-02-17 13:04:41" itemprop="dateCreated datePublished" datetime="2022-02-17T13:04:41+08:00">2022-02-17</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 22:50:59" itemprop="dateModified" datetime="2022-02-18T22:50:59+08:00">2022-02-18</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>opencv中有关图像绘制的部分</p>
<span id="more"></span>

<h1 id="一、绘制图形"><a href="#一、绘制图形" class="headerlink" title="一、绘制图形"></a>一、绘制图形</h1><p>Opencv4提供了circle（）函数用于绘制图形</p>
<h4 id="绘制圆形：circle（）函数原型"><a href="#绘制圆形：circle（）函数原型" class="headerlink" title="绘制圆形：circle（）函数原型"></a>绘制圆形：circle（）函数原型</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">void circle(InputOutputArray img, Point center, int radius, const Scalar &amp; color, int thickness = 1, int lineType = LINE_8, int shift = 0)</span><br></pre></td></tr></table></figure>

<p>img：需要绘制圆形的图像</p>
<p>center：圆形的圆心位置坐标</p>
<p>radius：圆形的半径，单位为像素</p>
<p>color：圆形的颜色</p>
<p>thickness：轮廓的宽度，如果数值为负，则绘制一个实心圆</p>
<p>lineType：边界的类型，可取值为FILLED、LINE_4、LINE_8和LINE_A4</p>
<p>shift：中心坐标和半径数值中的小数位数</p>
<p>该函数用于在一幅图像中绘制圆形图案，输入的参数分别是圆形的圆心位置、半径，以及边界线的宽度和线型。</p>
<h4 id="绘制直线：line（）函数原型"><a href="#绘制直线：line（）函数原型" class="headerlink" title="绘制直线：line（）函数原型"></a>绘制直线：line（）函数原型</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &amp; color, int thickness = 1, int lineType = LINE_8, int shift = 0)</span><br></pre></td></tr></table></figure>

<p>pt1：直线起点在图像中的坐标</p>
<p>pt2：直线终点在图像中的坐标</p>
<p>color：直线的颜色，用三通道表示</p>
<h4 id="绘制椭圆：ellipse（）函数原型"><a href="#绘制椭圆：ellipse（）函数原型" class="headerlink" title="绘制椭圆：ellipse（）函数原型"></a>绘制椭圆：ellipse（）函数原型</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &amp; color, int thickness = 1, int lineType = LINE_8, int shift)</span><br></pre></td></tr></table></figure>

<p>center：椭圆的中心坐标</p>
<p>axes：椭圆主轴大小的一半</p>
<p>angle：椭圆旋转的角度，单位为度</p>
<p>startAngle：椭圆弧起始的角度，单位为度</p>
<p>endAngle：椭圆弧终止的角度，单位为度</p>
<p>该函数通过选定椭圆中心位置和主轴大小唯一地确定一个椭圆，并且可以控制旋转角度改变椭圆在坐标系中的位置。通过椭圆弧起始和终止角度，可以绘制完整的椭圆或者一部分圆弧。当边界线thickness为负数的时候，将绘制一个实心的椭圆。</p>
<h4 id="绘制矩形：rectangle（）函数原型"><a href="#绘制矩形：rectangle（）函数原型" class="headerlink" title="绘制矩形：rectangle（）函数原型"></a>绘制矩形：rectangle（）函数原型</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &amp; color, int thickness = 1, int lineType = LINE_8, int shift = 0)</span><br><span class="line">void rectangle(InputOutputArray img, Rect rec, const Scalar &amp; color, int thickness = 1, int lineType = LINE_8, int shift = 0)</span><br></pre></td></tr></table></figure>

<p>pt1：矩形的一个顶点</p>
<p>pt2：矩形中与pt1相对的顶点，即两个点在对角线上</p>
<p>rec：矩形左上角顶点和长宽</p>
<p>绘制实心矩形的方法和前述一样，Rect表示的是矩形左上角像素坐标，以及矩形的长和宽，该类型定义的格式为Rect（像素的x坐标，像素的y坐标，矩形的宽，矩形的高），其中可以存放的数据类型也分别为int型（Rect2i或者Rect）、double类型（Rect2d）和float类型（Rect2f）</p>
<h4 id="绘制多边形：fillPoly（）函数原型"><a href="#绘制多边形：fillPoly（）函数原型" class="headerlink" title="绘制多边形：fillPoly（）函数原型"></a>绘制多边形：fillPoly（）函数原型</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">void fillPoly(InputOutputArray img, const Point ** pts, const int * npts, int  ncontours, const Scalar &amp; color, int lineType = LINE_8, int shift = 0, Point offset = Point())</span><br></pre></td></tr></table></figure>

<p> pts：多边形顶点数组，可以存放多个多边形的顶点坐标的数组</p>
<p>npts：每个多边形顶点数组中顶点的个数</p>
<p>ncontours：绘制多边形的个数</p>
<p>offset：所有顶点的可选偏移</p>
<p>多边形的顶点需要顺时针或者逆时针给出，通过控制边界线的宽度可以实现是否绘制实心多边形。</p>
<h4 id="文字生成：putText（）函数原型"><a href="#文字生成：putText（）函数原型" class="headerlink" title="文字生成：putText（）函数原型"></a>文字生成：putText（）函数原型</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">void putText(InputOutputArray img, const String &amp; text, Point org, int fontFace, double fontScale, Scalar color, int thickness = 1, int lintType = LINE_8, bool bottomLeftOrigin = false)</span><br></pre></td></tr></table></figure>

<p>text：输出到图像中的文字</p>
<p>org：图像中文文字字符串的左下角像素坐标</p>
<p>fontFace：字体类型的选择标志</p>
<p>bottomLeftOrigin：图像数据原点的位置。默认左上角，如果参数改为true，默认左下角</p>
<p>示例程序：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;opencv2\opencv.hpp&gt;</span>  <span class="comment">//加载OpenCV4的头文件</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> cv; <span class="comment">//OpenCV命名空间</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	Mat img = img.zeros(Size(<span class="number">512</span>,<span class="number">512</span>),CV_8UC3);  <span class="comment">//生成一个黑色图像用于绘制几何图形</span></span><br><span class="line">	<span class="comment">//绘制圆形</span></span><br><span class="line">	circle(img, Point(<span class="number">50</span>, <span class="number">50</span>), <span class="number">25</span>, Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>),<span class="number">-1</span>);  <span class="comment">//绘制一个实心圆，颜色为纯白</span></span><br><span class="line">	circle(img, Point(<span class="number">100</span>, <span class="number">50</span>), <span class="number">20</span>, Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>), <span class="number">4</span>);   <span class="comment">//绘制一个空心圆</span></span><br><span class="line">	<span class="comment">//绘制直线</span></span><br><span class="line">	line(img, Point(<span class="number">100</span>, <span class="number">100</span>), Point(<span class="number">200</span>, <span class="number">100</span>), Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>), <span class="number">2</span>,LINE_4, <span class="number">0</span>);  </span><br><span class="line">	<span class="comment">//绘制椭圆</span></span><br><span class="line">	ellipse(img, Point(<span class="number">300</span>, <span class="number">255</span>), Size(<span class="number">100</span>, <span class="number">70</span>), <span class="number">0</span>, <span class="number">0</span>, <span class="number">100</span>, Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>),<span class="number">-1</span>);</span><br><span class="line">	ellipse(img, RotatedRect(Point2f(<span class="number">150</span>, <span class="number">100</span>), Size2f(<span class="number">30</span>, <span class="number">20</span>), <span class="number">0</span>), Scalar(<span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>), <span class="number">2</span>); </span><br><span class="line">		<span class="built_in">vector</span>&lt;Point&gt; points;</span><br><span class="line">	<span class="comment">//用一些点来近似一个椭圆</span></span><br><span class="line">	ellipse2Poly(Point(<span class="number">200</span>, <span class="number">400</span>), Size(<span class="number">100</span>, <span class="number">70</span>), <span class="number">0</span>, <span class="number">0</span>, <span class="number">360</span>, <span class="number">2</span>, points);</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; points.size() - <span class="number">1</span>; i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span> (i == points.size() - <span class="number">1</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="comment">//椭圆最后一个点与第一个点连线</span></span><br><span class="line">			line(img, points[<span class="number">0</span>], points[i], Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>), <span class="number">2</span>);</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="comment">//当前点与后一个点连线</span></span><br><span class="line">		line(img, points[i], points[i + <span class="number">1</span>], Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>), <span class="number">2</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//绘制矩形</span></span><br><span class="line">	rectangle(img, Point(<span class="number">50</span>, <span class="number">400</span>), Point(<span class="number">100</span>, <span class="number">450</span>), Scalar(<span class="number">125</span>, <span class="number">125</span>, <span class="number">125</span>), <span class="number">-1</span>);</span><br><span class="line">	rectangle(img, Rect(<span class="number">400</span>, <span class="number">450</span>, <span class="number">60</span>, <span class="number">50</span>), Scalar(<span class="number">0</span>, <span class="number">125</span>, <span class="number">125</span>), <span class="number">2</span>);</span><br><span class="line">	<span class="comment">//绘制多边形</span></span><br><span class="line">	Point pp[<span class="number">2</span>][<span class="number">6</span>];</span><br><span class="line">	pp[<span class="number">0</span>][<span class="number">0</span>] = Point(<span class="number">72</span>, <span class="number">200</span>);</span><br><span class="line">	pp[<span class="number">0</span>][<span class="number">1</span>] = Point(<span class="number">142</span>, <span class="number">204</span>);</span><br><span class="line">	pp[<span class="number">0</span>][<span class="number">2</span>] = Point(<span class="number">226</span>, <span class="number">263</span>);</span><br><span class="line">	pp[<span class="number">0</span>][<span class="number">3</span>] = Point(<span class="number">172</span>, <span class="number">310</span>);</span><br><span class="line">	pp[<span class="number">0</span>][<span class="number">4</span>] = Point(<span class="number">117</span>, <span class="number">319</span>);</span><br><span class="line">	pp[<span class="number">0</span>][<span class="number">5</span>] = Point(<span class="number">15</span>, <span class="number">260</span>);</span><br><span class="line">	pp[<span class="number">1</span>][<span class="number">0</span>] = Point(<span class="number">359</span>, <span class="number">339</span>);</span><br><span class="line">	pp[<span class="number">1</span>][<span class="number">1</span>] = Point(<span class="number">447</span>, <span class="number">351</span>);</span><br><span class="line">	pp[<span class="number">1</span>][<span class="number">2</span>] = Point(<span class="number">504</span>, <span class="number">349</span>);</span><br><span class="line">	pp[<span class="number">1</span>][<span class="number">3</span>] = Point(<span class="number">484</span>, <span class="number">433</span>);</span><br><span class="line">	pp[<span class="number">1</span>][<span class="number">4</span>] = Point(<span class="number">418</span>, <span class="number">449</span>);</span><br><span class="line">	pp[<span class="number">1</span>][<span class="number">5</span>] = Point(<span class="number">354</span>, <span class="number">402</span>);</span><br><span class="line">	Point pp2[<span class="number">5</span>];</span><br><span class="line">	pp2[<span class="number">0</span>] = Point(<span class="number">350</span>, <span class="number">83</span>);</span><br><span class="line">	pp2[<span class="number">1</span>] = Point(<span class="number">463</span>, <span class="number">90</span>);</span><br><span class="line">	pp2[<span class="number">2</span>] = Point(<span class="number">500</span>, <span class="number">171</span>);</span><br><span class="line">	pp2[<span class="number">3</span>] = Point(<span class="number">421</span>, <span class="number">194</span>);</span><br><span class="line">	pp2[<span class="number">4</span>] = Point(<span class="number">338</span>, <span class="number">141</span>);</span><br><span class="line">	<span class="keyword">const</span> Point* pts[<span class="number">3</span>] = &#123; pp[<span class="number">0</span>],pp[<span class="number">1</span>],pp2 &#125;;  <span class="comment">//pts变量的生成</span></span><br><span class="line">	<span class="keyword">int</span> npts[] = &#123; <span class="number">6</span>,<span class="number">6</span>,<span class="number">5</span> &#125;;  <span class="comment">//顶点个数数组的生成</span></span><br><span class="line">	fillPoly(img, pts, npts, <span class="number">3</span>, Scalar(<span class="number">125</span>, <span class="number">125</span>, <span class="number">125</span>), <span class="number">8</span>);  <span class="comment">//绘制3个多边形</span></span><br><span class="line">	<span class="comment">//生成文字</span></span><br><span class="line">	putText(img, <span class="string">&quot;Learn OpenCV 4&quot;</span>, Point(<span class="number">100</span>, <span class="number">400</span>), <span class="number">2</span>, <span class="number">1</span>, Scalar(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>));</span><br><span class="line">	imshow(<span class="string">&quot;显示结果&quot;</span>, img);</span><br><span class="line">	waitKey(<span class="number">0</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;  <span class="comment">//程序结束</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<img src="https://img-blog.csdnimg.cn/17005c9a98954ff680d83be86d93074b.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="50%">



<p>感谢阅读！也欢迎大家关注小白博主，多多鼓励一下！ </p>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>杨大熊
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://yang-da-xiong.gitee.io/2022/02/17/opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E7%BB%98%E5%88%B6%E5%9B%BE%E5%BD%A2/" title="opencv学习笔记之绘制图形">https://yang-da-xiong.gitee.io/2022/02/17/opencv学习笔记之绘制图形/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/c/" rel="tag"># c++</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/02/16/opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E5%9B%BE%E5%83%8F%E9%80%8F%E8%A7%86%E5%8F%98%E6%8D%A2%E4%B8%8E%E6%9E%81%E5%9D%90%E6%A0%87%E5%8F%98%E6%8D%A2/" rel="prev" title="opencv学习笔记之图像透视变换与极坐标变换">
      <i class="fa fa-chevron-left"></i> opencv学习笔记之图像透视变换与极坐标变换
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/02/18/opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E7%BB%98%E5%88%B6%E5%9B%BE%E5%83%8F%E7%9B%B4%E6%96%B9%E5%9B%BE/" rel="next" title="opencv学习笔记之绘制图像直方图">
      opencv学习笔记之绘制图像直方图 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%89%8D%E8%A8%80"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E7%BB%98%E5%88%B6%E5%9B%BE%E5%BD%A2"><span class="nav-number">2.</span> <span class="nav-text">一、绘制图形</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BB%98%E5%88%B6%E5%9C%86%E5%BD%A2%EF%BC%9Acircle%EF%BC%88%EF%BC%89%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-number">2.0.0.1.</span> <span class="nav-text">绘制圆形：circle（）函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BB%98%E5%88%B6%E7%9B%B4%E7%BA%BF%EF%BC%9Aline%EF%BC%88%EF%BC%89%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-number">2.0.0.2.</span> <span class="nav-text">绘制直线：line（）函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BB%98%E5%88%B6%E6%A4%AD%E5%9C%86%EF%BC%9Aellipse%EF%BC%88%EF%BC%89%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-number">2.0.0.3.</span> <span class="nav-text">绘制椭圆：ellipse（）函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BB%98%E5%88%B6%E7%9F%A9%E5%BD%A2%EF%BC%9Arectangle%EF%BC%88%EF%BC%89%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-number">2.0.0.4.</span> <span class="nav-text">绘制矩形：rectangle（）函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BB%98%E5%88%B6%E5%A4%9A%E8%BE%B9%E5%BD%A2%EF%BC%9AfillPoly%EF%BC%88%EF%BC%89%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-number">2.0.0.5.</span> <span class="nav-text">绘制多边形：fillPoly（）函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%96%87%E5%AD%97%E7%94%9F%E6%88%90%EF%BC%9AputText%EF%BC%88%EF%BC%89%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-number">2.0.0.6.</span> <span class="nav-text">文字生成：putText（）函数原型</span></a></li></ol></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="杨大熊"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">杨大熊</p>
  <div class="site-description" itemprop="description">各类IT知识分享</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">58</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Yang-Da-xiong?tab=repositories" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Yang-Da-xiong?tab&#x3D;repositories" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/weixin_45775703?spm=1000.2115.3001.5343" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;weixin_45775703?spm&#x3D;1000.2115.3001.5343" rel="noopener" target="_blank"><i class="fab fa-codiepie fa-fw"></i>CSDN</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">杨大熊</span>
</div>

<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>
</span>
</div>

<span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>

<div class="theme-info">
<div class="powered-by"></div>
<span class="post-count">博客全站共56.5k字</span>
</div>
        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/schemes/clicklove.js"></script>
